home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Bazooka.lua < prev    next >
Text File  |  2010-08-31  |  6KB  |  154 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Bazooka + Projectile Rocket
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.bazooka={}
  10. cc.bazooka.rocket={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.bazooka.gfx_wpn=loadgfx("weapons/launcher.bmp")                    -- Weapon Image
  14. setmidhandle(cc.bazooka.gfx_wpn)
  15. cc.bazooka.gfx_pro=loadgfx("weapons/rocket.bmp")                    -- Projectile Image
  16. setmidhandle(cc.bazooka.gfx_pro)
  17. cc.bazooka.sfx_attack=loadsfx("rocketrelease.wav")                    -- Attack Sound
  18.  
  19. --------------------------------------------------------------------------------
  20. -- Weapon: Bazooka
  21. --------------------------------------------------------------------------------
  22.  
  23. cc.bazooka.id=addweapon("cc.bazooka","Bazooka",cc.bazooka.gfx_pro)    -- Add Weapon
  24.  
  25. function cc.bazooka.draw()                                            -- Draw
  26.     setblend(blend_alpha)
  27.     setalpha(1)
  28.     setcolor(255,255,255)
  29.     drawinhand(cc.bazooka.gfx_wpn,6,0)
  30.     -- HUD chargebar
  31.     if weapon_charge>0 and weapon_shots==0 then
  32.         hudchargebar(weapon_charge,100)
  33.     end
  34.     -- HUD Crosshair
  35.     if weapon_shots==0 then
  36.         hudcrosshair(6,3)
  37.     end
  38. end
  39.  
  40. function cc.bazooka.attack(attack)                                    -- Attack
  41.     if (weapon_shots<=0) then
  42.         -- Charge
  43.         if (attack==1) then
  44.             weapon_charge=weapon_charge+1                            -- Increase charge
  45.         end
  46.         -- Fire a projectile (on release/full charge)
  47.         if (attack==0 and weapon_charge>0) or (weapon_charge>=100) then
  48.             -- No more weapon switching!
  49.             useweapon(0)
  50.             playsound(cc.bazooka.sfx_attack)
  51.             weapon_shots=weapon_shots+1
  52.             id=createprojectile(cc.bazooka.rocket.id)
  53.             projectiles[id]={}
  54.             -- Ignore collision with current player at beginning
  55.             projectiles[id].ignore=playercurrent()
  56.             -- Set initial position of projectile
  57.             projectiles[id].x=getplayerx(0)+(6*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*10.0
  58.             projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*10.0
  59.             -- Initial movement
  60.             projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*20
  61.             projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*20
  62.             projectiles[id].x=projectiles[id].x-projectiles[id].sx
  63.             projectiles[id].y=projectiles[id].y-projectiles[id].sy
  64.             cc.bazooka.rocket.move(id,0)
  65.             -- Set speed of projectile
  66.             projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
  67.             projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
  68.             -- Effects
  69.             recoil(2)
  70.             -- End Turn
  71.             endturn()
  72.         end
  73.     end
  74. end
  75.  
  76. --------------------------------------------------------------------------------
  77. -- Projectile: Rocket
  78. --------------------------------------------------------------------------------
  79.  
  80. cc.bazooka.rocket.id=addprojectile("cc.bazooka.rocket")        -- Add Projectile
  81.  
  82. function cc.bazooka.rocket.draw(id)                            -- Draw
  83.     -- Setup draw mode
  84.     setblend(blend_alpha)
  85.     setalpha(1)
  86.     setcolor(255,255,255)
  87.     setscale(1,1)
  88.     -- Calculate projectile rotation
  89.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  90.     -- Draw projectile
  91.     drawimage(cc.bazooka.gfx_pro,projectiles[id].x,projectiles[id].y)
  92.     -- Draw Arrow if out of Screen
  93.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  94. end
  95.  
  96. function cc.bazooka.rocket.update(id)                        -- Update
  97.     -- Move
  98.     cc.bazooka.rocket.move(id,1)
  99. end
  100.  
  101. function cc.bazooka.rocket.move(id,fx)
  102.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  103.     -- Particle Tail
  104.     if (fx==1) then
  105.         particle(p_smoke,projectiles[id].x-math.sin(math.rad(rot))*7,projectiles[id].y+math.cos(math.rad(rot))*7)
  106.         particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
  107.         particlefadealpha(0.01)
  108.         particle(p_lightpuff,projectiles[id].x-math.sin(math.rad(rot))*6,projectiles[id].y+math.cos(math.rad(rot))*6)
  109.         particlefadealpha(0.04)
  110.     end
  111.     -- Wind + Gravity influence on speed
  112.     projectiles[id].sx=projectiles[id].sx+getwind()
  113.     projectiles[id].sy=projectiles[id].sy+getgravity()
  114.     -- Move (in substep loop for optimal collision precision)
  115.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  116.     msubx=projectiles[id].sx/msubt
  117.     msuby=projectiles[id].sy/msubt
  118.     for i=1,msubt,1 do
  119.         projectiles[id].x=projectiles[id].x+msubx
  120.         projectiles[id].y=projectiles[id].y+msuby
  121.         -- Collision
  122.         if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*3,projectiles[id].y-math.cos(math.rad(rot))*3)==1 then
  123.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  124.                 -- Cause damage
  125.                 arealdamage(projectiles[id].x,projectiles[id].y,100,45)
  126.                 -- Destroy terrain
  127.                 terrainexplosion(projectiles[id].x,projectiles[id].y,25,1)
  128.                 -- Crater
  129.                 grey=math.random(0,40)
  130.                 if math.random(0,1)==1 then
  131.                     terrainalphaimage(gfx_crater100,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  132.                 else
  133.                     terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  134.                 end
  135.                 -- Free projectile
  136.                 freeprojectile(id)
  137.                 return 1
  138.             end
  139.         else
  140.             projectiles[id].ignore=0
  141.         end
  142.         -- Water
  143.         if (projectiles[id].y)>getwatery()+5 then
  144.             -- Effects
  145.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  146.             playsound(sfx_hitwater1)
  147.             -- Free projectile
  148.             freeprojectile(id)
  149.             return 1
  150.         end
  151.     end
  152.     -- Scroll to projectile
  153.     scroll(projectiles[id].x,projectiles[id].y)
  154. end